<?php
/**
 * Created by PhpStorm.
 * User: coolinmind
 * Date: 07/01/2019
 * Time: 15:08
 */

namespace App\Services\UCenter;


use App\Services\UCenter\UCenter\UCenterLogic;

class UCenter
{
    /**
     * 更改用户信息
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function updateUserInfo($data)
    {
        $data = pick_array($data, [
            'id', 'other_info', 'real_name', 'nickname',
            'public_phone', 'wechat', 'email', 'qq', 'telephone','fax',
            'vis_fax','vis_phone','vis_wechat','vis_qq','vis_telephone',
            'province', 'city', 'county', 'detailed_address',
            'token', 'is_disturb', 'disturb_start', 'disturb_end']);
        ValidateUCenter::checkValidate($data, ['real_name' , 'other_info']);
        return (new UCenterLogic())->updateUserInfo($data);
    }
    /**
     * 根据id获取对方用户详情
     * @param $data
     */
    public function getInfoById($data)
    {
        $data = pick_array($data, ['id']);
        ValidateUCenter::checkValidate($data, ['id']);
        return (new UCenterLogic())->getInfoById($data);
    }

    /**
     * 修改登登录密码
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function editSelfLoginPassword($data)
    {
        ValidateUCenter::checkValidate($data, ['token', 'login_password', 'old_login_password', 're_login_password']);
        return (new UCenterLogic())->editSelfLoginPassword($data);
    }

    // 用户更改自己的支付密码
    public function editSelfPayPassword($data): array
    {
        ValidateUCenter::checkValidate($data, ['token', 'pay_password', 'old_pay_password', 're_pay_password']);
        return (new UCenterLogic())->editSelfPayPassword($data);
    }

    //用户进行实名认证
    public function authentication($data)
    {
        ValidateUCenter::checkValidate($data, [
            'token',
            'id',
            'front_id_photo',
            'back_id_photo',
            'full_photo',
            'name'
        ]);
        return (new UCenterLogic())->authentication($data);
    }

    // 企业进行实名认证
    public function corporateCertification($data)
    {
        ValidateUCenter::checkValidate($data, [
            'token',
            'mail',
            'name',
            'number',
            'address',
            'province',
            'legal_person',
            'social_unified_coding',
            'front_id_photo',
            'back_id_photo',
            'business_license'
        ]);
        return (new UCenterLogic())->corporateCertification($data);
    }

    //添加支付方式
    public function addPayment($data)
    {
        ValidateUCenter::checkValidate($data, ['token', 'name', 'type','account','bank_name', 'user_id', 'is_default']);
        return (new UCenterLogic())->addPayment($data);
    }

    /**
     * 获取支付方式列表
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getPaymentList($data)
    {
        ValidateUCenter::checkValidate($data, ['user_id']);
        return (new UCenterLogic())->getPaymentList($data);
    }

    /**
     * 删除支付方式
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function delPaymentById($data)
    {
        ValidateUCenter::checkValidate($data, ['id', 'user_id']);
        return (new UCenterLogic())->delPaymentById($data);
    }

    /**
     * 头像上传
     * @param $data
     * @return array
     */
    public function upload($data)
    {
        return (new UCenterLogic())->upload($data);
    }

    /**
     * 根据手机号获取短信验证码
     */
    public function getVerifyByPhone($data)
    {
        $data = pick_array($data, ['mobile', 'is_change_phone', 'token']);
        ValidateUCenter::checkValidate($data, ['mobile']);
        if (isset($data['is_change_phone']) && $data['is_change_phone']) {
            return (new UCenterLogic())->getVerifyByPhone($data, true);
        } else {
            return (new UCenterLogic())->getVerifyByPhone($data);
        }
    }

    /**
     * 验证短信验证码
     * @param $data
     * @return mixed
     */
    public function verifySms($data)
    {
        $data = pick_array($data, ['sms', 'token']);
        ValidateUCenter::checkValidate($data, ['sms', 'token']);
        return (new UCenterLogic())->verifySms($data);
    }

    /**
     * 验证新旧手机号及短信验证码并执行换绑
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function changePhone($data)
    {
        $data = pick_array($data, ['mobile', 'sms', 'user_id', 'token', 'old_mobile']);
        ValidateUCenter::checkValidate($data, ['mobile', 'sms', 'user_id', 'token', 'old_mobile']);
        return (new UCenterLogic())->changePhone($data);
    }

    /**
     * 签到
     * @param $data
     * @return mixed
     * @throws \App\Exceptions\RequestFailException
     */
    public function sign($data)
    {
        $data = pick_array($data, ['user_id', 'token']);
        ValidateUCenter::checkValidate($data, ['user_id', 'token']);
        return (new UCenterLogic())->sign($data);
    }

    /**
     * 检测用户是否签到
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function isSign($data)
    {
        $data = pick_array($data, ['user_id']);
        ValidateUCenter::checkValidate($data, ['user_id']);
        return (new UCenterLogic())->is_sign($data);
    }

    /**
     * 根据电话查找用户
     * @param $data
     * @return array
     * @throws \App\Exceptions\RequestFailException
     */
    public function getUserByPhone($data)
    {
        $data = pick_array($data, ['phone','name']);
        ValidateUCenter::checkValidate($data, ['phone','name']);
        return (new UCenterLogic())->getUserByPhone($data);
    }

    /**
     * 验证短信验证码及手机号并重置登录密码（忘记密码）
     * @param $data
     * @return array
     */
    public function changeLoginPwd($data)
    {
        $data = pick_array($data, ['phone', 'code', 'login_pwd', 're_login_pwd', 'token']);
        return (new UCenterLogic())->changeLoginPwd($data);
    }

    /**
     * 验证短信验证码并重置支付密码
     * @param $data
     * @return mixed
     */
    public function resetPayPassword($data)
    {
        $data = pick_array($data, ['code', 'pay_pass', 'sure_pay_pass', 'token', 'id']);
        return (new UCenterLogic())->resetPayPassword($data);
    }
}
